package com.sakura.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sakura.commonutils.R;
import com.sakura.eduservice.entity.EduCourse;
import com.sakura.eduservice.entity.EduTeacher;
import com.sakura.eduservice.service.EduCourseService;
import com.sakura.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "TeacherFrontController",description = "前台讲师列表的显示")
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @ApiOperation("分页查询讲师的方法")
    @PostMapping("list/{page}/{limit}")
    public R getTeacherList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);
        return R.ok().data(teacherService.getTeacherFrontList(pageTeacher));
    }

    @ApiOperation("讲师详情的功能")
    @PostMapping("info/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        //根据讲师id查询所讲的课程
        List<EduCourse> courseList = courseService.list(new QueryWrapper<EduCourse>()
                .eq("teacher_id", teacherId));
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
